﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using motelmanagement.common;
using System.Data;
using System.Data.OleDb;
namespace motelmanagement.dao
{
    class RoleDAO
    {
        SqlUtil sqlUtil = new SqlUtil();
        OleDbCommand cmd = null;
        private string strSql = null;
        public DataTable getALLRole() {
            cmd = new OleDbCommand("Select * from Role");
            sqlUtil.Load(cmd);
            return sqlUtil;
        }
        public DataTable getRole(int roleID)
        {
            cmd = new OleDbCommand("Select * from Role where role_id=@id");
            cmd.Parameters.Add("id", SqlDbType.Int).Value = roleID;
            sqlUtil.Load(cmd);
            return sqlUtil;
        }
        public void insertRole(string roleName) {
            cmd = new OleDbCommand("Insert into Role(role_name) Values(@name)");
            cmd.Parameters.Add("name",SqlDbType.NText).Value=roleName;
            sqlUtil.ExecuteNoneQuery(cmd);
        }
        public void updateRole(int roleID,string roleName)
        {
            cmd = new OleDbCommand("Update Role Set role_name = @name Where role_id=@id");
            cmd.Parameters.Add("name", SqlDbType.NText).Value = roleName;
            cmd.Parameters.Add("id", SqlDbType.Int).Value = roleID;
            sqlUtil.ExecuteNoneQuery(cmd);
        }
        public void deleteRole(int roleID)
        {
            cmd = new OleDbCommand("Delete From Role Where role_id=@id");
            cmd.Parameters.Add("id", SqlDbType.Int).Value = roleID;
            sqlUtil.ExecuteNoneQuery(cmd);
        }
    }
}
